package com.nidu.demo.notify.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.notify.convertor.NotifyMessageConvertor;
import com.nidu.demo.notify.convertor.NotifyMessageCriteriaConvertor;
import com.nidu.demo.notify.dto.NotifyMessageCO;
import com.nidu.demo.notify.dto.NotifyMessagePageQry;
import com.nidu.demo.notify.gateway.NotifyMessageGateway;
import com.nidu.demo.notify.model.NotifyMessage;
import com.nidu.demo.notify.model.NotifyMessageCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 站内信消息分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class NotifyMessagePageQryExe {

    private final NotifyMessageGateway gateway;
    private final NotifyMessageConvertor convertor;
    private final NotifyMessageCriteriaConvertor criteriaConvertor;

    public PageResponse<NotifyMessageCO> execute(NotifyMessagePageQry qry) {
        // 1. 转换查询条件
        NotifyMessageCriteria criteria = criteriaConvertor.toDataObject(qry);

        // 2. 执行分页查询
        PageResponse<NotifyMessage> page = gateway.pageByCondition(criteria);

        // 3. 转换为DTO并返回
        List<NotifyMessageCO> notifyMessageCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(notifyMessageCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }

}
